package com.walle.bio;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author zhangjiapeng
 * @Package com.walle.bio
 * @Description: ${todo}
 * @date 2019/1/18 11:53
 */
public class TimeServer2 {

    private static final int PORT = 9999;

    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(PORT);
            System.out.println("TimeServer started and listening port " + PORT);
            Socket socket = null;
            TimeServerHandlerExcutePool pool = new TimeServerHandlerExcutePool(3,10,10);
            while (true){
                socket =  serverSocket.accept();
                pool.excute(new TimeServerHandler(socket));
            }
        } catch(Exception e) {
            if(serverSocket != null){
                System.out.println("TimeServer closed");
                serverSocket.close();
                serverSocket = null;
            }
        }
    }
}
